package org.neo4j.neoclipse.connection;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.IDescriptionProvider;
import org.neo4j.neoclipse.Activator;
import org.neo4j.neoclipse.Icons;
import org.neo4j.neoclipse.graphdb.GraphDbServiceManager;

/**
 * Provides a label and icon for objects of type {@link PropertiesTreeData}. 
 * @since 3.2 
 */
public class PropertiesLabelProvider extends LabelProvider implements
		ILabelProvider, IDescriptionProvider {
  

	public Image getImage(Object element) {
		if (element instanceof PropertiesTreeData){
			return PlatformUI.getWorkbench().getSharedImages().getImage(
					ISharedImages.IMG_OBJS_INFO_TSK); 
			}
		else if ( element instanceof Alias )
        {
            Alias alias = (Alias) element;
            GraphDbServiceManager graphDbServiceManager = Activator.getDefault().getGraphDbServiceManager();
            if ( graphDbServiceManager.isRunning() && graphDbServiceManager.getCurrentAlias().equals( alias ) )
            {
                return Icons.NEW_ALIAS_ENABLED.image();

            }

        }
        return Icons.NEW_ALIAS_DISABLED.image();
		//return null;
	}

	public String getText(Object element) {
		if (element instanceof PropertiesTreeData) {
			PropertiesTreeData data = (PropertiesTreeData) element;
			return data.getName() + "= " + data.getValue(); //$NON-NLS-1$
		}  
		else if ( element instanceof Alias )
        {
            Alias alias = (Alias) element;

            String label = alias.getName();

            return label + "( " + alias.getUri() + " )";

        }
		return null;
	}

	public String getDescription(Object anElement) {
		if (anElement instanceof PropertiesTreeData) {
			PropertiesTreeData data = (PropertiesTreeData) anElement;
			return "Property: " + data.getName(); //$NON-NLS-1$
		}
		return null;
	}
  
}
